package com.lkd.plcs7.direct.s7;

import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
import com.lkd.plcs7.direct.config.PlcConfigProperties;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Data
public class PlcConnection {

    private S7PLC s7PLC;

    public PlcConnection(PlcConfigProperties plcConfigProperties )
    {// 创建PLC对象
        S7PLC s7PLC = new S7PLC(plcConfigProperties.getType(), plcConfigProperties.getAddress());
        boolean b1 = s7PLC.readBoolean("v1.0");
        boolean flag = s7PLC.checkConnected();
        if (flag){
            log.info("测试读取数据value："+flag);
            log.info("ip为"+plcConfigProperties.getAddress()+"的plc连接成功！");
            this.s7PLC = s7PLC;
        }else {
            throw new RuntimeException("ip为"+plcConfigProperties.getAddress()+"的plc连接失败！");
        }
    }

}



